//
//  LandingView.m
//  豆瓣
//
//  Created by lanou3g on 15/12/9.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "LandingView.h"

@implementation LandingView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
    }
    
    return self;
    
}

- (void)addAllViews{
    //用户名
    
    self.nameLable = [[UILabel alloc] init];
    self.nameLable.text = @"用户名:";
    [self addSubview:self.nameLable];
    
    
    //用户名textField

    self.nameTextField = [[UITextField alloc] init];
    self.nameTextField.clearButtonMode = UITextFieldViewModeAlways;
    self.nameTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.nameTextField.placeholder = @"请输入用户名";
    [self addSubview:self.nameTextField];
    
    
    
    
    //密码

    self.passwordLable = [[UILabel alloc] init];
    self.passwordLable.text = @"密码:";
    [self addSubview:self.passwordLable];
    
    
    //密码textField

    self.passwordTextField = [[UITextField alloc] init];
    self.passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.passwordTextField.placeholder = @"请输入密码";
    self.passwordTextField.secureTextEntry = YES;
    self.passwordTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.passwordTextField];
    
    
    //登陆button
    self.logingButton = [UIButton buttonWithType:UIButtonTypeSystem];
   
    self.logingButton.backgroundColor = [UIColor blueColor];
    [self.logingButton setTitle:@"登陆" forState:UIControlStateNormal];
    [self.logingButton addTarget:self action:@selector(logingButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.logingButton.layer.masksToBounds = YES;
    self.logingButton.layer.cornerRadius = 4;
    [self addSubview:self.logingButton];
  
    

    
    //注册button
    self.registeredButton = [UIButton buttonWithType:UIButtonTypeSystem];
  
    [self.registeredButton setTitle:@"注册" forState:UIControlStateNormal];
    self.registeredButton.backgroundColor = [UIColor orangeColor];
    [self.registeredButton addTarget:self action:@selector(registeredButtonAction) forControlEvents:UIControlEventTouchUpInside];
    self.registeredButton.layer.masksToBounds = YES;
    self.registeredButton.layer.cornerRadius = 4;
    [self addSubview:self.registeredButton];
   
    
    
    
    
}


- (void)logingButtonAction{
    [self endEditing:YES];
    
}


- (void)passwordButtonAction{
    [self endEditing:YES];
}


- (void)registeredButtonAction{
    [self endEditing:YES];
}


//布局子视图
- (void)layoutSubviews
{
    self.nameLable.frame = CGRectMake(50, 50, self.frame.size.width / 5, 30);
    
    self.nameTextField.frame = CGRectMake(CGRectGetMaxX(self.nameLable.frame), self.nameLable.frame.origin.y, self.frame.size.width/ 5 * 4 - 100, self.nameLable.frame.size.height);
    
    
    
    self.passwordLable.frame = CGRectMake(self.nameLable.frame.origin.x, CGRectGetMaxY(self.nameLable.frame) + 20, self.nameLable.frame.size.width, self.nameLable.frame.size.height);
   
    self.passwordTextField.frame = CGRectMake(CGRectGetMaxX(self.passwordLable.frame), self.passwordLable.frame.origin.y, self.frame.size.width/ 5 * 4 - 100, self.passwordLable.frame.size.height);
    
    
    CGFloat w = self.frame.size.width / 9;
    
    
    self.logingButton.frame = CGRectMake(w, CGRectGetMaxY(self.passwordLable.frame) + 50, w*3, 40);
    
    self.registeredButton.frame = CGRectMake(CGRectGetMaxX(self.logingButton.frame) + w, self.logingButton.frame.origin.y, w*3, 40);
    
    
}


@end
